package com.hgk.common.common.tools;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.view.View;

public class DialogUtil {
	
	/**
	 * 加载中对话框
	 */
	public  static ProgressDialog mLoadingDialog;

	/**
	 * 普通对话框
	 */
	public static AlertDialog.Builder builder;
	/**
	 * 显示普通对话框
	 * 
	 * @param title
	 *            标题
	 * @param message
	 *            内容
	 * @param view
	 *            自定义展示view 如果view!=null 则不显示message
	 * @param textLeft
	 *            左边按钮的文字
	 * @param leftListener
	 *            左边按钮监听
	 * @param textRight
	 *            右边按钮的文字
	 * @param rightListener
	 *            右边按钮的监听
	 */
	public static void showAlertDialog(Activity context,String title,String message,
			View view,String textLeft,DialogInterface.OnClickListener leftListener,
			String textRight,DialogInterface.OnClickListener rightListener,boolean cancelable){
			builder=null;
			builder=new AlertDialog.Builder(context);

		builder.setTitle(title);
		if (view != null) {
			builder.setView(view);
		}else{
			if(message!=null&&!message.equalsIgnoreCase(""))
				builder.setMessage(message);
		}
		builder.setPositiveButton(textLeft, leftListener);
		builder.setNegativeButton(textRight, rightListener);
		builder.setCancelable(cancelable);
		builder.show();
	}
	
//	public static AlertDialog.Builder getAlertDialog(Activity context,String title,String message,
//			View view,String textLeft,OnRippleCompleteListener leftListener,
//			String textRight,OnRippleCompleteListener rightListener){
//		final AlertDialog mApplyPop = new AlertDialog.Builder(context).create();
//		mApplyPop.show();
//		mApplyPop.setContentView(R.layout.playing_dialog_layout);
//		mApplyPop.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
//		RippleView mRvApply = (RippleView) mApplyPop.getWindow().findViewById(R.id.rv_apply_class);
//		RippleView mRvAttend = (RippleView) mApplyPop.getWindow().findViewById(R.id.rv_attend_class);
//		EditText mEdtContent = (EditText) mApplyPop.getWindow().findViewById(R.id.edt_apply_class_content);
//		TextView mBtnApplyClose = (TextView) mApplyPop.getWindow().findViewById(R.id.tv_apply_class_close);
//		mEdtContent.setVisibility(View.GONE);
//		mBtnApplyClose.setOnClickListener(new OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				mApplyPop.dismiss();
//			}
//		});
//		mRvApply.setOnRippleCompleteListener(leftListener);
//		mRvAttend.setOnRippleCompleteListener(rightListener);
//		return builder;
//	}
	
	public static void showAlertItemDialog(Activity context,String title,String[] items,DialogInterface.OnClickListener listner){
		builder=null;
		builder=new AlertDialog.Builder(context);
		builder.setTitle(title);
		builder.setItems(items,listner);
		builder.setCancelable(true);
		builder.show();
	}
	
	public  static void showAlertItemDialog(Activity context,String title,String[] items,DialogInterface.OnClickListener listner,boolean cancelable){
		builder=null;
		builder=new AlertDialog.Builder(context);
		builder.setTitle(title);
		builder.setItems(items,listner);
		builder.setCancelable(cancelable);
		builder.show();
	}
	
	/**
	 * 显示加载中的对话框
	 * 
	 * @param message
	 *            提示信息
	 */
	public static void showLoadingDialog(Activity context,String message) {
		if (mLoadingDialog == null) {
			mLoadingDialog = new ProgressDialog(context);
		}
		mLoadingDialog.setMessage(message);
		mLoadingDialog.setCancelable(false);
		if (!mLoadingDialog.isShowing()) {
			mLoadingDialog.show();
		}
	}
	
	public static void showLoadingDialog(Activity context,String message,boolean isCabncelable) {
		try {
			
		
		if (mLoadingDialog == null) {
			mLoadingDialog = new ProgressDialog(context);
		}
		mLoadingDialog.setMessage(message);
		mLoadingDialog.setCancelable(isCabncelable);
		if (!mLoadingDialog.isShowing()) {
			mLoadingDialog.show();
		}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 显示加载中对话框
	 */
	public static void showLoadingDialog(Activity context) {
		showLoadingDialog(context,"提交中...");
	}
	
	public static void showLoadingDialog(Activity context,boolean isCabncelable) {
		showLoadingDialog(context,"提交中...",isCabncelable);
		
	}

	/**
	 * 关闭加载中的对话框
	 */
	public static void closeDialog() {
		if (mLoadingDialog != null && mLoadingDialog.isShowing()) {
			try {
				mLoadingDialog.dismiss();
			} catch (IllegalArgumentException e) {
				
			}
			
		}
	}

	/**
	 * 删除全部对话框
	 */
	public static void delDialog() {
		closeDialog();
		if (mLoadingDialog != null) {
			mLoadingDialog = null;
		}
		if (builder != null) {
			builder = null;
		}
	}
	
	
}
